package com.luo.controller;

import com.luo.constant.MessageConstant;
import com.luo.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zoro
 * @date 2021年08月31
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/getUsername.do")
    public Result getUsername() {
        try {
            User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS, user);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS);
        }

    }
}
